package it.polimi.travelDreamEJB.web.beans;

import java.util.Date;
import java.util.List;

import it.polimi.travelDreamEJB.basicproductmanagement.BasicProductMgr;
import it.polimi.travelDreamEJB.basicproductmanagement.dto.FlightDTO;
import it.polimi.travelDreamEJB.basicproductmanagement.dto.HotelDTO;
import it.polimi.travelDreamEJB.basicproductmanagement.dto.SearchFlightDTO;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

import org.primefaces.event.RowEditEvent;

@ManagedBean(name="flightBean")
@ViewScoped
public class FlightBean {
	
	@EJB
	private BasicProductMgr bpm;
	
	private FlightDTO flight;
	
	private SearchFlightDTO searchFlight;
	
	private List<FlightDTO> flightList;
	
	public FlightBean() {
		searchFlight = new SearchFlightDTO();
		flight = new FlightDTO();
	}
	
	public FlightDTO getFlight() {
		return flight;
	}
	
	public void setFlight(FlightDTO flight) {
		this.flight = flight;
	}
	
	public SearchFlightDTO getSearchFlight() {
		return searchFlight;
	}
	
	public void setSearchFlight(SearchFlightDTO searchFlight) {
		this.searchFlight = searchFlight;
	}

	public List<FlightDTO> getFlightList() {
		return flightList;
	}

	public void setFlightList(List<FlightDTO> flightList) {
		this.flightList = flightList;
	}

	public String save() {
		bpm.save_flight(flight);
		return "basic?faces-redirect=true";
	}
	
	public void find() {

		flightList = bpm.findFlight(searchFlight);

	}

	public void delete(RowEditEvent event) {

		flight = ((FlightDTO) event.getObject());
		bpm.delete_flight(flight);
		flightList.remove(flight);

	}

	public void update(RowEditEvent event) {

		bpm.update_flight(((FlightDTO) event.getObject()));

	}

}